<template>
  <div class="addRegistration">
    <el-card shadow="never">
      <div class="header">
        <div class="page-header">
          <el-page-header @back="goBack" content="报名" style="margin-bottom: 20px">
          </el-page-header>
        </div>

        <div class="registration">
          <!--     标题     -->
          <el-form  label-width="120px">
            <el-form-item label="活动" prop="activityTitle">
              <el-input
                  disabled
                  v-model="activityForm.activityTitle"
                  :rows="10"></el-input>
            </el-form-item>
            <el-form-item label="补充" prop="registrationContent">
              <el-input
                  type="textarea"
                  v-model="registrationForm.registrationContent"
                  :rows="10"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button :disabled="isDisabled" type="primary" @click="addRegistration">确认</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import {addRegistration, getActivityById} from "@/api/allApi";

export default {
  data() {
    return {
      registrationForm:{},
      activityForm:{},
      user:'',
      isDisabled:false
    }
  },
  created() {
    this.user = JSON.parse(window.localStorage.getItem('access-user'))
  },
  methods:{
    getActivityById() {
      getActivityById(this.$route.params.activityId).then(res=>{
        this.activityForm = res.data.data
      })
    },
    goBack() {
      this.$router.back();
    },
    addRegistration() {
      this.registrationForm.userId = this.user.userId
      this.registrationForm.activityType = this.$route.params.activityType
      this.registrationForm.activityId = this.activityForm.activityId
      addRegistration(this.registrationForm).then(res=>{
        if (res.data.success) {
          this.$message.success(res.data.data)
          if (Number(this.$route.params.activityType) === 1){
            this.$router.push({
              path: "/userLayout/activityParticulars/" + this.activityForm.activityId,
            });
          }
          else {
            this.$router.push({
              path: "/userLayout/volunteerParticulars/" + this.activityForm.activityId,
            });
          }
        }
        else {
          this.$message.error(res.data.errorMsg)

          this.$router.push({
            path: "/userLayout/activityParticulars/" + this.activityForm.activityId,
          });
        }
      })
    },
  },
  mounted() {
    this.getActivityById()
  }
}
</script>

<style lang="less" scoped>
  .addRegistration {
    width: 80%;
    margin: 30px auto;
    min-width: 900px;
    flex-wrap: wrap;
    border-radius: 5px;

    .registration {
      padding: 30px;
      min-height: 450px;
      margin: 0 auto;
    }
  }
</style>